<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@page import="org.corp.agi.web.constant.WebConstant"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib uri="http://agi.corp.org/authz" prefix="authz"%>
<%@ page import="th.co.mfec.agi.basic.common.constant.ProjectConstant" %>
<%@ taglib uri="http://agi.corp.org/authz" prefix="authz"%>
<%@ page import="th.co.mfec.mca.common.PrivConst"%>
<div id="content">
<div id="dialoginfo"></div>
<s:form id="form" action="userGroupAuthorization-updateUserGroup.htm" method="POST">
<s:hidden id="page" name="inquiry" />
<s:hidden id="requestPage" name="requestPage" value="%{pagingBean.currentPage}" />

<s:hidden id="isObjListAll" name="isObjListAll" value="bean.isObjListAll" />
      <div class="topic">Display Page</div>
      <div id="searchResult">
          <div class="subTopic">Display screen name or object name record braked by user group ID</div>
          <div class="tableSearchResult">
          <%-- 
            <div class="pagefound">
              <table>
                <tr>
                  <td class="L">
                  	<strong>Page</strong> <s:property value="%{pagingBean.currentPage}"/>/ <s:property value="%{pagingBean.pageCount}"/>
                  </td>
                
                  <td class="R">
                    <div class="pagenum">
                   	<a href="javascript:changePage(1)"><span>&laquo;</span></a>&nbsp;&nbsp;
                   	<a href="javascript:changePage(<s:property value="%{pagingBean.perviousPage}"/>)"><span>&#8249;</span></a>&nbsp;&nbsp;
                   	<s:iterator status="rowstatus" value="%{pagingBean.displayPage}" >
                   		<a href="javascript:changePage(<s:property />)"><s:property /></a>&nbsp;&nbsp;
                   	</s:iterator>
                   	<a href="javascript:changePage(<s:property value="%{pagingBean.nextPage}"/>)"><span>&#8250;</span></a>&nbsp;&nbsp;
                   	<a href="javascript:changePage(<s:property value="%{pagingBean.pageCount}"/>)"><span>&raquo;</span></a>&nbsp;&nbsp;
                   	</div>
                  </td>
                </tr>
              </table>
            </div>
            --%>
            <table>
            	<!-- Topic Result -->	
			    <tr>
	              	<th nowrap="nowrap" class="icon"><label>
	                    <!--<s:checkbox name="checkedLabel" disabled="true"/>-->
	                  </label>
	                </th>
                	<th nowrap="nowrap">Screen Name/Object Name</th>
              	</tr>
              	<!-- Start Result -->	
              	<!-- Start Validate data not found -->
			    <s:if test="%{bean==null}">
			    		<br />
			  			<tr>
				  			<td align="center">
				  				<div class="alert"><s:text name="label.noRecordFound"/></div>
				  			</td>	
				  			<td colspan="23" ></td>
			  			</tr>
			  	</s:if>
			  	<!-- End Validate data not found -->
	  			<s:else>
	  					<!-- listCustomMasterObjectAuthByUsg Result -->
		              	<s:if test="%{bean.listCustomMasterObjectAuthByUsg!=null}">
			              	<s:iterator value="bean.listCustomMasterObjectAuthByUsg">
				            <tr>
				            	<s:if test='%{oagEnable=="T"}'>
				              		<td class="icon"><s:checkbox id="%{objId}" name="checkedId" value="true" fieldValue="%{objId}" onclick="doCheckParent(this)" /></td>
				                </s:if>
				                <s:elseif test='%{oagEnable=="F"}'>
				                	<td class="icon"><s:checkbox id="%{objId}" name="checkedId" value="false" fieldValue="%{objId}" onclick="doCheckParent(this)" /></td>
				                </s:elseif>
				                <!-- <td class="name"><s:property value="objName"/></td> -->
				                <!-- check bold/thin font to display objName -->
								<s:if test="%{objLvl==1}">
									<td class="name"><font><b><s:property value="objName"/></b></font></td>
								</s:if>
								<s:elseif test="%{objLvl==2}">
				                	<td class="name">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<s:property value="objName"/></td>
				                </s:elseif>
				            </tr>
				            </s:iterator>
			            </s:if>
			            <!-- listMasterObject Result -->
			            <s:elseif test="%{bean.listMasterObject!=null}">
				            <s:iterator value="bean.listMasterObject">
				            <tr>
				              	<td class="icon"><s:checkbox id="%{objId}" name="checkedId" value="false"  fieldValue="%{objId}" onclick="doCheckParent(this)" /></td>
								<!-- check bold/thin font to display objName -->
								<s:if test="%{objLvl==1}">
									<td class="name"><font><b><s:property value="objName"/></b></font></td>
								</s:if>
								<s:elseif test="%{objLvl==2}">
				                	<td class="name">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<s:property value="objName"/></td>
				                </s:elseif>
				            </tr>
				            </s:iterator>
			            </s:elseif>
	            </s:else>
			    <!-- End Result -->		    
			  </table>
			  <%-- 
			  <div class="pagefound">
			  <table>
                <tr>
                  <td class="L">
                  	<strong>Found</strong> <s:property value="%{pagingBean.totalRows}"/> group(s)
                  	&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
                  	<strong>Display</strong>&nbsp;
                    <s:textfield id="rowsPerPage" name="rowsPerPage" value="%{pagingBean.rowsPerPage}" cssStyle="width: 60px; text-align: right;"/>
                    &nbsp;
                    row(s) per page
                  	</td>
                  <td class="R">
                    <div class="pagenum">
                   	<a href="javascript:changePage(1)"><span>&laquo;</span></a>&nbsp;&nbsp;
                   	<a href="javascript:changePage(<s:property value="%{pagingBean.perviousPage}"/>)"><span>&#8249;</span></a>&nbsp;&nbsp;
                   	<s:iterator status="rowstatus" value="%{pagingBean.displayPage}" >
                   		<a href="javascript:changePage(<s:property />)"><s:property /></a>&nbsp;&nbsp;
                   	</s:iterator>
                   	<a href="javascript:changePage(<s:property value="%{pagingBean.nextPage}"/>)"><span>&#8250;</span></a>&nbsp;&nbsp;
                   	<a href="javascript:changePage(<s:property value="%{pagingBean.pageCount}"/>)"><span>&raquo;</span></a>&nbsp;&nbsp;
                   	</div>
                  </td>
                </tr>
              </table>
              </div>
              --%>
            	<br />
            	<br />
          </div>
      </div>
        <!-- / search result -->
        <div class="button">
		  <table align="center">
		  <tr>
		    <td><authz:authorize granted="<%=PrivConst.S060101%>" ><span id="button"><a id="saveButton"><span><s:text name="button.save" /></span></a></span></authz:authorize></td>
		    <td><span id="button"><a id="clearButton"><span><s:text name="button.clear" /></span></a></span></td>
		    <td><span id="button"><a id="backButton"><span><s:text name="button.back" /></span></a></span></td>
		  </tr>
		  </table>
		</div>
		<div class="hr"></div>   
        </s:form>
</div>
<script type="text/javascript">

//function changePage(page) {
//	$j("#requestPage").val(page);
//	$j("#form")
//		.attr("action","userGroupAuthorization-getAuthListByGroup.htm")
//		.submit(); 
//}

function doCheckParent(checkbox){
	$j(":checkbox[id^='" + checkbox.value.substring(0,4) + "']").each(function(){

		if(this.value.substring(0,4) != '00' && this.checked == true) // Parent can not be "Not Checked" if children are still "Checked".
			$j(":checkbox[id='" + checkbox.value.substring(0,4) +"00']").attr("checked",true); // Checked Parent
	});
		
}

$j(document).ready(function() { 
	$j("#saveButton").click(function () {
	 		$j("#form")
  	 		.attr("action","userGroupAuthorization-updateUserGroup.htm")
  	 		.submit();	 
	});
	
	$j("#clearButton").click(function () {
	 		$j("#form")
  	 		.attr("action","userGroupAuthorization-getAuthListByGroup.htm")
  	 		.submit();	 
	});
	
	$j("#backButton").click(function () {
	 		$j("#form")
  	 		.attr("action","userGroupAuthorization-init.htm")
  	 		.submit();	 
	});
	
});
</script>